package hotelManagement.hotelArtifacts;
import org.springframework.orm.hibernate3.support.*;
import org.hibernate.Hibernate;
import java.util.*;

public class RoomInfoDaoImpl extends HibernateDaoSupport implements RoomInfoDao{
	public RoomInfo get(String roomNumber){
		RoomInfo ri = (RoomInfo)getHibernateTemplate().get(RoomInfo.class, roomNumber);
		return ri;
	}
	
	public List<RoomInfo> get(int type){
		List<RoomInfo> ri = getHibernateTemplate().find("from RoomInfo r where r.type=" + type);
		return ri;
	}
	
	public void save(RoomInfo roomInfo){
		getHibernateTemplate().save(roomInfo);
	}
	
	public void delete(RoomInfo roomInfo){
		getHibernateTemplate().delete(roomInfo);
	}
	
	public void delete(String roomNumber){
		getHibernateTemplate().delete(get(roomNumber));
	}
	
	public void update(RoomInfo roomInfo){
		getHibernateTemplate().update(roomInfo);
	}
	
	public Long getRoomNumber(){
		List roomList = getHibernateTemplate().find("select count(roomNumber) from RoomInfo");
		if(roomList == null)
			return new Long(0);
		
		return (Long)roomList.get(0);
	}
	
	public String getRoomStatusByRoomNumber(String roomNumber){
		List<RoomInfo> ri = getHibernateTemplate().find("from RoomInfo r where r.roomNumber='" + roomNumber+"'");
		return ri.get(0).getStatus();
	}
	
	public List<RoomInfo> getAll(){
		return getHibernateTemplate().find("from RoomInfo");
	}
}
